package org.video.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import org.video.mine.R;
import org.video.mine.databinding.TvOtherLayoutBinding;
import org.video.mine.entity.DongHuaEntity;
import org.video.mine.model.ClickModel;

import java.util.List;

public class TvOtherAdapter extends RecyclerView.Adapter<TvOtherAdapter.ViewHolder> {

    List<DongHuaEntity> dongHuaEntities;
    Context context;
    String viewType;

    public TvOtherAdapter(List<DongHuaEntity> dongHuaEntities, Context context, String viewType) {
        this.dongHuaEntities = dongHuaEntities;
        this.context = context;
        this.viewType = viewType;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding binding;
        binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.tv_other_layout, parent, false);
        return new ViewHolder(binding);
    }


    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        DongHuaEntity dongHuaEntity = dongHuaEntities.get(position);
        ((TvOtherLayoutBinding) holder.getTitleBinding()).setTvInfo(dongHuaEntity);
        ((TvOtherLayoutBinding) holder.getTitleBinding()).setOnclick(new ClickModel());
        ((TvOtherLayoutBinding) holder.getTitleBinding()).setContext(context);
    }

    @Override
    public int getItemCount() {
        return dongHuaEntities.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (viewType.equals("donghua")){
            return 1;
        }else {
            return 0;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        ViewDataBinding titleBinding = null;

        public ViewHolder(ViewDataBinding titleBinding) {
            super(titleBinding.getRoot());
            this.titleBinding = titleBinding;
        }

        public ViewDataBinding getTitleBinding(){
            return titleBinding;
        }
    }
}
